package myDemo.bobo.number.impl;

import myDemo.bobo.number.PermutationProcessor;

public final class FullPermutation {

    public  static <T> void permutate(T a[], PermutationProcessor<T> processor) {
        permutate(a, 0, a.length,processor);

    }
   static <T>  void permutate(T a[], int m, int n,PermutationProcessor<T> processor) {
        int i;
        T t;
        if (m < n - 1) {
            permutate(a, m + 1, n,processor);
            for (i = m + 1; i < n; i++) {
                swap(a, m, i);
                permutate(a, m + 1, n,processor);
                swap(a, m, i);
            }
        } else {
            processor.process(a);
        }
    }

    private static <T> void swap(T[] a, int m, int i) {
        T t;
        t = a[m];
        a[m] = a[i];
        a[i] = t;
    }
}